<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
</head>
<script src="js/jquery.js"></script>
<script>
    /*function emailRe(){
        var re=/^[1-9]\d{8,13}@qq.com$/;
    }*/
    //////////////////  /////////////////////////////////////////////
    
    function ageRe() {
        var yn=false;
        var age=$("input[name=age]");
        if(isNaN(age.val())){
            age.next("span").html("请输入数值类型");
        }else{
            if(parseInt(age.val())>0&&parseInt(age.val())<=120){
                yn=true;
                age.next("span").html("");
            }else{
                age.next("span").html("请输入合适的年龄");
            }
        }
        return yn;
    }

    function idCardRe() {
        var idCard=$("input[name='idCard']");
        var idCardRe=/^[1-9]\d{17}$/;
        if(idCardRe.test(idCard.val())){
            idCard.next("span").html("");
            return true;
        }else{
            idCard.next("span").html("身份证格式不匹配");
            return false;
        }
    }
    function pwdRe(){
        var pwd=$("input[name='pwd']");
        if(pwd.val()!=null && pwd.val()!=''){
            pwd.next("span").html("");
            return true;
        }
        pwd.next("span").html("请输入密码");
        return false;
    }
    function nameRe(){
        var yn=false;
        var name=$("input[name='name']");
        if(name.val()!=null&&name.val()!=''){
            var params="name="+name.val();
            $.ajax({
                url:"/user/selUserName",
                type:"get",
                async:false,
                data:params,
                success:function (data) {
                    /*alert(data);*/
                    if(data==1){
                        name.next("span").html("用户名重复请重新输入");
                        // return false;
                    }else{
                        name.next("span").html("");
                        yn=true;
                        // return true;
                    }
                }
            });
        }else{
            name.next("span").html("请输入用户名");
        }
        return yn;
    }
    function emailRe(){
        var yn=false;
        var email=$("input[name=email]");
        var emailRe=/^\w+@\w+(\.[A-Za-z]{2,3}){1,2}$/;
        if(emailRe.test(email.val())){
            $.ajax({
                url: "/user/selEmail",
                async: false,
                type: "get",
                data: "email="+email.val(),
                success:function (data) {
                    if(data==1){
                        email.next("span").html("邮箱重复");
                    }else{
                        yn=true;
                        email.next("span").html("");
                    }
                }
            });
        }else{
            email.next("span").html("邮箱格式不对");
        }
        return yn;
    }
    function selSemesterAll(){
        $.getJSON("/semester/selSemesterAll","",function (data) {
            var str="";
            for(var i=0;i<data.length;i++){
                str+="<option value='"+data[i].id+"'>"+data[i].termName+"</option>";
            }
            $("select[name=semesterId]").html(str);
        });
    }
    $(function () {
        selSemesterAll();
        $("input[name='pwd']").blur(pwdRe);
        $("input[name='name']").blur(nameRe);
        $("input[name=age]").blur(ageRe);
        $("input[name='idCard']").blur(idCardRe);
        $("input[name='email']").blur(emailRe);

        $("form").submit(function () {
            var pwd=pwdRe();
            var name=nameRe();
            var age=ageRe();
            var idCard=idCardRe();
            var email=emailRe();
            alert(pwd+"|"+name+"|"+age+"|"+idCard+"|"+email);
            if(pwd&&name&&age&&idCard&&email){
                return true;
            }else{
                return false;
            }
        })
    });
</script>
<body>
<form action="/user/register1" method="post" enctype="multipart/form-data">
    用户名：<input type="text" name="name"><span></span><br/>
    密码：<input type="text" name="pwd"><span></span><br/>
    邮箱：<input type="email" name="email"><span></span><br/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    女:<input checked="checked" type="radio" value="0" name="sex">男:<input type="radio" value="1" name="sex"><br/>
    班级：<input type="text" name="clbum" required><br/>
    学期：<select name="semesterId"></select><br/>
    身份证：<input type="text" name="idCard"><span></span><br/>
    年龄：<input type="text" name="age"><span></span><br/>
    照片：<input type="file" name="file" required><span></span><br/>
    <input type="submit" value="注册">    注：注册后为激活要同过邮件来激活
</form>
<a href="/login">登入</a>
</body>
</html>